home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
ATBSB002.ZIP
/
DEMOTOOL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-16
|
11KB
|
356 lines
/*
DEMOTOOL.C -- program to demonstrate the abilities of
Tool Bar and Status Bar controls implemented in ESTOOLS.DLL
and ERROR.DLL
Copyright (C) Eugene Sokolov 1992-93, (516)632-7892,
esokolov@sbchm1.chem.sunysb.edu
(SUNY at Stony Brook, NY 11794-3400)
You can freely copy, change or redistribute this file as long
as this notice remains intact.
Last edition 12/16/93 (mm/dd/yy)
*/
#define STRICT
#include <windows.h>
#include "estools0.h"
#include "esdefs.h"
#include "error0.h"
#define STATBAR_HEIGHT 22
LRESULT CALLBACK MainWndProc ( HWND, UINT, WPARAM, LPARAM );
HINSTANCE hInst;
BOOL InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (long (FAR PASCAL*)())MainWndProc;
// windows of this class.
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(TBICON) );
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = MAKEINTRESOURCE(TBMENU);
wc.lpszClassName = "ESDemoTools";
return (RegisterClass(&wc));
}
/************************************************************************/
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow(
"ESDemoTools", // See RegisterClass() call.
"ES Toolbar Demo", // Text for window title bar.
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, // Window style.
CW_USEDEFAULT, // Default horizontal position.
CW_USEDEFAULT, // Default vertical position.
CW_USEDEFAULT, // Default width.
CW_USEDEFAULT, // Default height.
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
return (FALSE);
ShowWindow(hWnd, nCmdShow); // Show the window
UpdateWindow(hWnd); // Sends WM_PAINT message
return (TRUE); // Returns the value from PostQuitMessage
}
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam )
{
static HWND hwndTBar;
static HWND hwndSBar;
switch (message)
{
case WM_CREATE:
{
POINT pnt;
RECT rc;
GetClientRect( hWnd, &rc );
pnt.x=pnt.y=0;
hwndTBar=CreateToolBar( hInst, (LPSTR)MAKEINTRESOURCE(TOOLBAR), hWnd, pnt );
if( !hwndTBar )
{
MessageBox( hWnd, "Could not create Tool Bar window", NULL, MB_OK );
PostMessage( hWnd, WM_CLOSE, 0, 0L );
}
hwndSBar=CreateStatusWindow( WS_CHILD | WS_VISIBLE, 0, rc.bottom-STATBAR_HEIGHT,
rc.right, STATBAR_HEIGHT, hWnd, hInst );
if( !hwndSBar )
{
MessageBox( hWnd, "Could not create Status Bar window", NULL, MB_OK );
PostMessage( hWnd, WM_CLOSE, 0, 0L );
}
break;
}
case WM_SIZE:
MoveWindow( hwndSBar, 0, HIWORD(lParam)-STATBAR_HEIGHT, //Position
//the SB window on the
//bottom of the parent
LOWORD(lParam), STATBAR_HEIGHT, TRUE );
break;
case WM_COMMAND:
/* The following WM_COMMAND message processing was NOT intended to be
nicely written and serves as an example only to show the abilities
of the Tool Bar control. */
switch( wParam )
{
case ID_CMD1:
case ID_CMD2:
case ID_CMD3:
case ID_CMD4:
case ID_CMD5:
{
/* This simply prints the wParam of the WM_COMMAND message
which is equal to the ID number of the pressed TB button
*/
/* Old way: */
HDC hdc;
char buffer[64];
hdc = GetDC( hWnd );
wsprintf( buffer,"Message WM_COMMAND, wParam=0x%X (%u), button # %d",
wParam, wParam, GetButtonNumber( hwndTBar, wParam ) );
TextOut( hdc, 10, 20, buffer, lstrlen( buffer ) );
ReleaseDC( hWnd, hdc );
/* New way throught Status Bar, look how much simpler
it is */
ErrorHandler( hwndSBar, "Message WM_COMMAND, wParam=0x%X (%u), button # %d",
wParam, wParam, GetButtonNumber( hwndTBar, wParam ) );
/* ErrorHandler is an actual export from ERROR.DLL */
break;
}
case 1100:
case 1200:
case 1300:
case 1400:
case 1500:
/* Toggle disable/enable button */
{
int button=(wParam-1100)/100;
HMENU hm;
hm=GetMenu( hWnd );
CheckMenuItem( hm, wParam,
(GetMenuState( hm, wParam, MF_BYCOMMAND )&MF_CHECKED)?
MF_UNCHECKED:MF_CHECKED );
ES_TB_Toggle_Enable_Disable_Demo( hwndTBar, button );
// This function actually calls SendMessage API which sends
// a message to hwndTBar window to change the corresponding
// style (explanation and source for these functions is sent to
// the registred users only).
//
// Of course you can try to 'Spy' the messages. But I do
// not think the effort would be worth $15. Anyway, you are
// not allowed to use it in your programs unless you are
// registered.
}
break;
case 1101:
case 1201:
case 1301:
case 1401:
case 1501:
/* Toggle standard/auto 2 state button */
{
int button=(wParam-1100)/100;
HMENU hm;
hm=GetMenu( hWnd );
CheckMenuItem( hm, wParam,
(GetMenuState( hm, wParam, MF_BYCOMMAND )&MF_CHECKED)?
MF_UNCHECKED:MF_CHECKED );
ES_TB_Toggle_Standard_Auto2State_Demo( hwndTBar, button );
// you need to register to get the documentation on this
// option. Read the explanation above.
}
break;
case 1102:
case 1202:
case 1302:
case 1402:
case 1502:
/* Toggle standard/2 state button */
{
int button=(wParam-1100)/100;
HMENU hm;
hm=GetMenu( hWnd );
CheckMenuItem( hm, wParam,
(GetMenuState( hm, wParam, MF_BYCOMMAND )&MF_CHECKED)?
MF_UNCHECKED:MF_CHECKED );
ES_TB_Toggle_Standard_2State_Demo( hwndTBar, button );
// you need to register to get the documentation on this
// option. Look up there εεε
break;
}
case 2001:
case 2002:
case 2003:
case 2004:
case 2005:
/*
This function calls SendMessage which sends the corresponding
message to hwndTBar to set the number of buttons per row.
Although you could specify 0 in resource header to get horizontal
tool bar, here you have to supply the actual number, 0 does not
work - the call will be ignored
*/
ES_TB_Set_Number_of_Controls_Demo( hwndTBar, wParam-2000 ); //Register!
ShowWindow( hwndTBar, SW_SHOW );
/*
Calls to this and following functions will hide the TB from
the screen. You need to show the window explicitly. I removed
this call to ShowWindow from DLL to give a programmer the
possibility to move the window after it's style was changed before
the window is displayed. Thus you can override the default
positions of window and so on.
*/
break;
/*
case 2006:
I want to point out that there is no example on something
like
ES_TB_Toggle_Popup_Child_Demo( hwndTBar );
It is not because it is undocumented but because it is
not implemented. This simply does not work, Windows 3.x
cannot convert WS_POPUP to WS_CHILD and back. Or at least I
can say I do not know about this possibility. If you want
this, you need to destroy the TB with one style and create
with another. Or tell me how to make it work.
I may include an additionla function to the ESTOOLS.DLL
to have this work done, but it won't be done throught a SendMessage
API but simply by destruction of one window and creation of another.
*/
case 2007:
{
/* Toggles caption/no caption TB */
HMENU hm;
hm=GetMenu( hWnd );
CheckMenuItem( hm, wParam,
(GetMenuState( hm, wParam, MF_BYCOMMAND )&MF_CHECKED)?
MF_UNCHECKED:MF_CHECKED